package com.sg.service.biz.bff.impl;

import cn.hutool.core.bean.BeanUtil;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.bff.req.BffQueryCodeListComReqDto;
import com.sg.dto.biz.bff.res.BffQueryCodeListComRespDto;
import com.sg.dto.biz.bff.res.BffTypeEncodingDto;
import com.sg.service.biz.bff.TypeCodeService;
import com.sg.common.exception.Assert;
import com.wicket.okrframework.integration.InductionRecordService;
import com.wicket.okrframework.integration.TypeCodeService;
import com.wicket.okrframework.integration.dto.*;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.stream.Collectors;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class TypeCodeServiceImpl implements TypeCodeService {
    @Resource
    com.sg.service.biz.framework.TypeCodeService fwBaseTypeCodeClient;
    @Resource
    com.sg.service.biz.framework.InductionRecordService fwBaseInductionRecordClient;
    @Resource
    private RedisUtil redisUtil;


    /**
     * B查询编码列表（公共）[644]
     * gen by moon at 9/27/2022, 9:36:46 AM
     */
    @Trace(operationName = "B查询编码列表（公共）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffQueryCodeListComRespDto queryCodeListCom(BffQueryCodeListComReqDto reqDto) {


        QueryCodeListComRespDto queryCodeListComRespDto_1 = null;
//步骤0: D1-1查询编码列表(公共) - queryCodeListCom
        QueryCodeListComRespDto queryCodeListComRespDto = null;
        QueryCodeListComReqDto queryCodeListComReqDto = new QueryCodeListComReqDto();
        queryCodeListComReqDto.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:14561_1
        if (reqDto != null) {
            queryCodeListComReqDto.setTypeCode(reqDto.getTypeCode());//sourceId:11019_1
        }

        /*D1-1查询编码列表(公共)[648]   */
        Assert.isNull(queryCodeListComReqDto.getTypeCode(), "B查询编码列表（公共）-D1-1查询编码列表(公共)-类型的编码不能为空", false);
        Assert.isNull(queryCodeListComReqDto.getSubjectLifeCycle(), "B查询编码列表（公共）-D1-1查询编码列表(公共)-主体生命周期不能为空", false);
        queryCodeListComRespDto = fwBaseTypeCodeClient.queryCodeListCom(queryCodeListComReqDto).getData();
        Assert.isTrue(queryCodeListComRespDto == null || queryCodeListComRespDto.getTypeEncodingList() == null || queryCodeListComRespDto.getTypeEncodingList().size() == 0, "返回值不能为空", false);

        queryCodeListComRespDto_1 = queryCodeListComRespDto;

        BffQueryCodeListComRespDto retData = new BffQueryCodeListComRespDto();
        if (queryCodeListComRespDto_1 != null) {
            retData.setTypeEncodingList(queryCodeListComRespDto_1.getTypeEncodingList().stream().map(item -> BeanUtil.toBean(item, BffTypeEncodingDto.class)).collect(Collectors.toList()));//sourceId:11034_1
        }


        return retData;
    }


    //
}
